package com.chen.mobiletwo.controller;

import com.chen.mobiletwo.service.UserService;
import jakarta.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@CrossOrigin//跨域
@RestController//遵循RestFul
@RequestMapping("v2/User/")
public class UserController {
    private static final Logger logger= LoggerFactory.getLogger(UserController.class);//日志getLogger需要传入的类名
    @Resource
    private RedisTemplate<String ,String> redisTemplate;//Redis工具类
    @Resource
    UserService userService;

    /**
     * 重置密码到123456
     * @param uId 用户id
     * @return json
     */
    @PostMapping("reSetPwd")
    private String reSetPwd(@RequestParam("uId") int uId){
        return userService.reSetPwd(uId);
    }

    /**
     * 重置密码
     * @param uId 用户id
     * @param pwd 密码
     * @return json
     */
    @PostMapping("setPwd")
    private String setPwd(@RequestParam("uId") int uId,@RequestParam("pwd") String pwd){
        return userService.setPwd(uId,pwd);
    }

    /**
     * 软删除
     * @param uId 用户id
     * @return json
     */
    @DeleteMapping("delUser")
    private String delUser(@RequestParam("uId") int uId){
        return userService.delUser(uId);
    }

    /**
     * 查询用户列表
     * @param uName 用户名
     * @param start 起始位置
     * @param cnt 数量
     * @return json
     */
    @GetMapping("getUserList")
    private String getUserList(@RequestParam("uName") String uName,
                               @RequestParam("start") int start,
                               @RequestParam("cnt") int cnt)
    {
        return userService.getUserList(uName,start,cnt);
    }

    /**
     * 获取用户详情
     * @param phone 电话
     * @param weChat 微信
     * @param email qq
     * @return json
     */
    @GetMapping("getDetailList")
    private String getDetailList(@RequestParam("phone") String phone,
                                 @RequestParam("weChat") String weChat,
                                 @RequestParam("email") String email)
    {
        return userService.getDetailList(phone,weChat,email);
    }

    /**
     * 新增用户
     * @param uName 用户名
     * @return json
     */
    @PostMapping("addUser")
    private String addUser(@RequestParam("uName") String uName)
    {
        return userService.addUser(uName);
    }

    /**
     * 新增用户详情
     * @param uId 用户id
     * @param phone 电话
     * @param weChat 微信
     * @param qqNum qq
     * @param email 邮箱号
     * @return json
     */
    @PostMapping("addUserDetail")
    private String addUserDetail(
                                 @RequestParam("uId") int uId,
                                 @RequestParam("phone") String phone,
                                 @RequestParam("weChat") String weChat,
                                 @RequestParam("qqNum") String qqNum,
                                 @RequestParam("email") String email

    )
    {
        return userService.addUserDetail(uId,phone,weChat,qqNum,email);
    }
}
